package cate.game.play.skill.passive.god;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDSkill;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 每回合结束时，损失自身5%的生命，为生命最低的1名友方单位恢复12%的生命，若生命最低的单位是自身或自身生命低于25%则无法触发。
 */
public class 奉献PH extends PassiveHandler {

	private double 损失系数;

	private double 恢复系数;

	private double 最低系数;

	//损失系数=500&恢复系数=1200&最低系数=2500
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		损失系数 = args.getWDouble("损失系数", 0d);
		恢复系数 = args.getWDouble("恢复系数", 0d);
		最低系数 = args.getDouble("最低系数", 0d);
	}

	@Override
	public void onRoundEnd(ActionCtx action) {
		if (skill.owner.attr.total().hpCurRate() <= 最低系数) {
			return;
		}
		Fighter target = TargetSelector.findOne(skill.owner, action.getTeamVs(), new TargetFilterParam().scopeSet(GDSkill.Scope.WE).smallAttrSet(GDAttr.HP_CUR));
		if (target != null) {
			double damage = skill.owner.attr.total().hpTotal() * 损失系数;
			skill.owner.attr.passiveHurt(action, skill.owner, damage);
			double heal = target.attr.total().hpTotal() * 恢复系数;
			target.attr.passiveHeal(action, skill.owner, heal);
		}
	}
}
